package com.wolfman.socket.server.handler;

import com.alibaba.fastjson.JSONObject;
import com.wolfman.socket.server.controller.PersonController;
import com.wolfman.socket.server.controller.impl.PersonControllerImpl;
import com.wolfman.socket.server.pojo.Person;
import com.wolfman.socket.server.pojo.RequestType;
import com.wolfman.socket.server.pojo.SocketRequest;

/**
 * @Title
 * @Description
 * @Author WolfMan
 * @Date 2022/11/25 12:57
 * @Email 2370032534@qq.com
 */
public class Handler {

    private static PersonController personController = new PersonControllerImpl();

    public Object handle(String s) {
        //解析数据
        SocketRequest parse = JSONObject.parseObject(s, SocketRequest.class);
        RequestType requestType = parse.getHeader().getType();
        Person person = JSONObject.parseObject(parse.getBody(),Person.class);
        switch (requestType) {
            case SAVEPERSON:
                return personController.saverPerson(person);
            case SELECTPERSON:
                return personController.selectPerson(person);
            default:
                return "no support controller";
        }
    }

}
